package com.ruoyi.screen.controller;
import com.ruoyi.screen.dto.*;
import com.ruoyi.screen.entity.ServiceType;
import com.ruoyi.screen.service.IStatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

// StatsController.java
@RestController
@RequestMapping("/api/stats")
@RequiredArgsConstructor
public class StatsController {
    private final IStatsService statsService;

    @GetMapping("/weekly-usage")
    public ResponseEntity<Long> getWeeklyServiceUsage() {
        return ResponseEntity.ok(statsService.getWeeklyServiceUsage());
    }

    @GetMapping("/total-usage")
    public ResponseEntity<Long> getTotalServiceUsage() {
        return ResponseEntity.ok(statsService.getTotalServiceUsage());
    }

    @GetMapping("/total-users")
    public ResponseEntity<Long> getTotalUserCount() {
        return ResponseEntity.ok(statsService.getTotalUserCount());
    }

    @GetMapping("/weekly-service-details")
    public ResponseEntity<List<ServiceUsageDTO>> getWeeklyServiceUsageDetails() {
        return ResponseEntity.ok(statsService.getWeeklyServiceUsageDetails());
    }

    @GetMapping("/service-types")
    public ResponseEntity<List<ServiceType>> getAllServiceTypes() {
        return ResponseEntity.ok(statsService.getAllServiceTypes());
    }

    @GetMapping("/credit-distribution")
    public ResponseEntity<List<CreditDistributionDTO>> getCreditScoreDistribution() {
        return ResponseEntity.ok(statsService.getCreditScoreDistribution());
    }

    @GetMapping("/user-profile")
    public ResponseEntity<Map<String, List<UserProfileDistributionDTO>>> getUserProfileDistribution() {
        return ResponseEntity.ok(statsService.getUserProfileDistribution());
    }

    @GetMapping("/income-distribution")
    public ResponseEntity<List<IncomeDistributionDTO>> getIncomeDistributionByCounty() {
        return ResponseEntity.ok(statsService.getIncomeDistributionByCounty());
    }

    @GetMapping("/county-user-count")
    public ResponseEntity<List<CountyUserCountDTO>> getUserCountByCounty() {
        return ResponseEntity.ok(statsService.getUserCountByCounty());
    }

    @GetMapping("/service-weekly-usage/{serviceId}")
    public ResponseEntity<List<WeeklyUsageDTO>> getWeeklyUsageByService(
            @PathVariable Integer serviceId) {
        return ResponseEntity.ok(statsService.getWeeklyUsageByService(serviceId));
    }
}